package com.zues.rabbit_self_test.service.work_queue;

import com.rabbitmq.client.CancelCallback;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.DeliverCallback;
import com.zues.rabbit_self_test.utils.RabbitMqUtils;

/**
 * @ClassName WorkingQueueConsumer
 * @Description 两消费者同时消费工作队列，消费者1
 * @Author zeus
 * @Date 6/13/2025 8:37 上午
 * @Version 1.0
 **/
public class WorkingQueueConsumer1 {

    private final static String QUEUE_NAME = "working_queue";

    public static void main(String[] args) throws Exception {

        Channel channel = RabbitMqUtils.getChannel();
        channel.queueDeclare(QUEUE_NAME, true, false, false, null);

        DeliverCallback deliverCallback = (consumerTag, delivery) -> {
            String receivedMessage = new String(delivery.getBody(), "UTF-8");
            System.out.println("consumerTag = " + consumerTag);
            System.out.println("接收到消息：" + receivedMessage);
        };

        CancelCallback cancelCallback = (consumerTag) -> {
            System.out.println(consumerTag + "消费者取消消息消费接口回调逻辑");
        };
        System.out.println("C1等待接收消息....");
        channel.basicConsume(QUEUE_NAME, true, deliverCallback, cancelCallback);

    }
}
